package com.qen.collection.bitset;

import java.util.BitSet;

public class BitSetExample {

    public static void main(String[] args) {
        BitSet bitSet = new BitSet(16);

        bitSet.set(1);
        bitSet.set(3);
        bitSet.set(5);
        bitSet.set(7);

        for (int i = 0; i < bitSet.size(); i++) {
            boolean bit = bitSet.get(i);
            System.out.println("Bit at index " + i + ":" + bit);
        }
        System.out.println("=============");

        boolean value = bitSet.get(3);
        System.out.println("Bit at index 3:" + value);

        bitSet.clear(3);
        System.out.println("Bit at index 3:" + bitSet.get(3));

        BitSet anotherBitSet = new BitSet(16);
        anotherBitSet.set(3);
        anotherBitSet.set(7);

        bitSet.or(anotherBitSet);

        for (int i = 0; i < bitSet.size(); i++) {
            boolean bit = bitSet.get(i);
            System.out.println("Bit at index " + i + ":" + bit);
        }

    }

}
